package cn.edu.nuc.carsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.edu.nuc.carsystem.dto.PageInfo;
import cn.edu.nuc.carsystem.model.Bank;
import cn.edu.nuc.carsystem.model.City;
import cn.edu.nuc.carsystem.model.Conrtuny;
import cn.edu.nuc.carsystem.service.interfaces.BankService;
import cn.edu.nuc.carsystem.service.interfaces.CityService;
/**
 * 银行controller
 * @author 杨晓庆
 *
 */
@RequestMapping("/car/bank")
@Controller
public class BankController {
   @Autowired
   private BankService bankService;
   /**
    * 添加银行
    * @param city
    * @return
    */
   @RequestMapping(value="/insert",method=RequestMethod.POST)
	public String insert(Bank bank){
    Integer count=bankService.insert(bank);
    if(count>0){
	   return "redirect:/car/bank/findAll";
    }
    else
       return "/car/bank/addBank";
   }
   /**
    * 跳转添加银行页面
    * @param city
    * @return
    */
   @RequestMapping(value="/addBank",method=RequestMethod.GET)
	public String addBank(Bank Bank){
   
       return "car/addBank";
   }
   /**
    * 分页查询所有银行
    * @param current
    * @return
    */
   @RequestMapping(value="/findAll",method=RequestMethod.GET)
  	public ModelAndView findAll(@RequestParam(name="current",defaultValue="1") Integer current,Bank bank){
      ModelAndView model=new ModelAndView("car/banklist");
      PageInfo pi=bankService.findAll(bank,current);
      model.addObject("pi",pi);
      System.out.println("length"+pi.getItem().size());
      System.out.println("banklist"+pi);
  	  return model;
  	}
   /**
    * 返回给用户
    * @param current
    * @param bank
    * @return
    */
   @RequestMapping(value="/User/findAll",method=RequestMethod.GET)
  	public ModelAndView UserfindAll(@RequestParam(name="current",defaultValue="1") Integer current,Bank bank){
      ModelAndView model=new ModelAndView("custome/banklist");
      PageInfo pi=bankService.findAll(bank,current);
      model.addObject("pi",pi);
      System.out.println("length"+pi.getItem().size());
      System.out.println("banklist"+pi);
  	  return model;
  	}

}
